<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semantic/dist/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
    <script src="${ctx}/resources/semantic/dist/semantic.min.js" type="text/javascript"></script>
    <title>发布职位</title>
    <style>
        input{width:100px;height:30px;line-height:30px;}


    </style>
</head>
<body>
<div class="ui segment" id="n-title" style="height: 100px">
    <div id="firstTitle">职位基本信息</div>
</div>
<div class="ui segments" id="n-body">
    <div class="ui segment" id="n-page">
        <div class="ui segment" id="n-content">
            <form class="ui form">
                <div id="positionInfo">
                    <div class="field">
                        <label><span style="color: red">*</span>项目名称</label>
                        <input type="text" name="name" id="name" value="${job.name}" placeholder="请输入项目名称">
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>项目介绍</label>
                        <div class="ui input">
                            <textarea name="description" id="description" placeholder="请输入项目介绍">${job.description}</textarea>
                        </div>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>所在城市</label>
                        <select name="cityId" id="cityId"  class="ui search dropdown" multiple="" >
                            <option value="0" selected disabled>-- 请选择 --</option>
                            <c:forEach items="${cities}" var="city">
                               <option value="${city.id}">${city.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>专业要求</label>
                        <select name="specialty" id="specialty"  class="ui search dropdown" >
                            <option value="0" selected disabled>-- 请选择 --</option>
                            <c:forEach items="${specs}" var="spec">
                                <c:choose>
                                    <c:when test="${job.specialty == spec.id }">
                                        <option value="${spec.id}" selected="selected">${spec.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${spec.id}">${spec.name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>学历要求</label>
                        <select name="degree" id="degree"  class="ui search dropdown" >
                            <c:choose>
                            <c:when test="${job.degree == 1 }">
                                <option value="1" selected>本科</option>
                                <option value="2">硕士</option>
                                <option value="3">博士</option>
                                <option value="4">博士后</option>
                            </c:when>
                            <c:when test="${job.degree == 2 }">
                                <option value="1" >本科</option>
                                <option value="2"selected>硕士</option>
                                <option value="3">博士</option>
                                <option value="4">博士后</option>
                            </c:when>
                            <c:when test="${job.degree == 3 }">
                                <option value="1" >本科</option>
                                <option value="2">硕士</option>
                                <option value="3" selected>博士</option>
                                <option value="4">博士后</option>
                            </c:when>
                            <c:when test="${job.degree == 4 }">
                                <option value="1" >本科</option>
                                <option value="2">硕士</option>
                                <option value="3">博士</option>
                                <option value="4" selected>博士后</option>
                            </c:when>
                             <c:otherwise>
                                <option value="1" selected>本科</option>
                                <option value="2">硕士</option>
                                <option value="3">博士</option>
                                <option value="4" >博士后</option>
                            </c:otherwise>
                            </c:choose>
                        </select>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>医学生来源</label>
                        <select name="source" id="source"  class="ui search dropdown" multiple="" >
                            <option value="0" selected disabled>-- 请选择 --</option>
                            <c:forEach items="${schools}" var="sch">
                                <c:choose>
                                    <c:when test="${job.talentSource == sch.id }">
                                        <option value="${sch.id}" selected="selected">${sch.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${sch.id}">${sch.name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>毕业年份</label>
                        <select name="graduateDate" id="graduateDate"  class="ui search dropdown">
                            <c:choose>
                                <c:when test="${job.graduateDate == 2020 }">
                                    <option value="2020" selected>2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:when>
                                <c:when test="${job.graduateDate == 2021 }">
                                    <option value="2020" >2020年</option>
                                    <option value="2021" selected>2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:when>
                                <c:when test="${job.graduateDate == 2022 }">
                                    <option value="2020" >2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" selected>2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:when>
                                <c:when test="${job.graduateDate == 2023 }">
                                    <option value="2020" >2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" selected>2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:when>
                                <c:when test="${job.graduateDate == 2024 }">
                                    <option value="2020" >2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" selected>2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:when>
                                <c:when test="${job.graduateDate == 2025 }">
                                    <option value="2020" >2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" selected>2025年</option>
                                </c:when>
                                <c:otherwise>
                                    <option value="2020" selected>2020年</option>
                                    <option value="2021" >2021年</option>
                                    <option value="2022" >2022年</option>
                                    <option value="2023" >2023年</option>
                                    <option value="2024" >2024年</option>
                                    <option value="2025" >2025年</option>
                                </c:otherwise>
                            </c:choose>
                        </select>
                    </div>
                    <div class="field">
                        <label><span style="color: red">*</span>海外背景</label>
                        <select name="returnee" id="returnee"  class="ui search dropdown">
                            <c:choose>
                            <c:when test="${job.returnee == 1 }">
                            <option value="2" >NO</option>
                            <option value="1" selected>YES</option>
                            </c:when>
                            <c:otherwise>
                                <option value="2" selected>NO</option>
                                <option value="1" >YES</option>
                            </c:otherwise>
                            </c:choose>
                        </select>
                    </div>
                </div>
                <input  type="hidden" id="jobId" value="${job.id}">
                <input  type="hidden" id="createBy" value="${createBy}">

                <c:choose>
                <c:when test="${model == 'create' }">
                <div class="ui segment" id="btn-next2">
                    <div class="fluid ui button" id="next" >确认发布</div>
                </div>
                </c:when>
                <c:when test="${model == 'edit' }">
                <div class="ui segment" id="cont-next">
                    <div class="fluid ui button" id="update" style="display: inline;width: 48%;float: left">保存</div>
                    <div class="fluid ui button" id="del" style="display: inline;width: 48%;float: right">删除</div>
                    <br><br>
                </div>
                </c:when>
                </c:choose>
            </form>
        </div>
    </div>
</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script type="text/javascript">

    wx.config({
        debug: false,
        appId: "${config.appid}",
        timestamp: ${config.currenttimestamp},
        nonceStr: "${config.nonceStr}",
        signature: "${config.signatureStr}",
        jsApiList: ['checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideOptionMenu']
    });


    var handler = {
        activate: function() {
            if($(this).attr('id') == 'del') {
                if(confirm("确认删除该职位吗？")) {
                    var id = $('#jobId').val();
                    var deluri = "${ctx}/wechat/hunter/school/schJob/del/" + id;
                    $.ajax({
                        url: deluri,
                        type: "get",
                        success: function(){
                           alert("删除成功");
                            var uri = '${ctx}/wechat/hunter/school/schJob/list'
                            window.location.href = uri;
                        }
                    });
                }
            };
            if($(this).attr('id') == 'next' || 'update') {
                var id  = $("#jobId").val();
                var name     = $('#name').val()
                var cityIds      = $("#cityId").val();
                var cityId = "";
                if (cityIds) {
                    cityId = cityIds.join(",");
                }
                var specialty    = $("#specialty").val();
                var degree = $("#degree").val();
                var description = $('#description').val();
                var sources   = $("#source").val();
                var source = "";
                if (sources) {
                    source = sources.join(",");
                }
                var graduateDate = $("#graduateDate").val();
                var returnee = $("#returnee").val();
                var createBy = $("#createBy").val();

                if(!name || name == "") {
                    alert("请完善所有必填项");
                    return false;
                }
                if(!cityId || cityId == "") {
                    alert("请完善所有必填项");
                    return false;
                }
                if(specialty == 0) {
                    alert("请完善所有必填项");
                    return false;
                }
                if(degree == 0) {
                    alert("请完善所有必填项");
                    return false;
                }
                if(!description || description=="") {
                    alert("请完善所有必填项");
                    return false;
                }
                if(source == 0) {
                    alert("请完善所有必填项");
                    return false;
                }
                if(graduateDate == 0) {
                    alert("请完善所有必填项");
                    return false;
                }
                if(returnee == 0) {
                    alert("请完善所有必填项");
                    return false;
                }

                $(this).addClass('disabled');
                var that = this;
                var param = {};
                var postUrl = '';
                if (!id) {
                    postUrl = '${ctx}/wechat/hunter/school/schJob/saveJob';
                } else {
                    postUrl = '${ctx}/wechat/hunter/school/schJob/editJob';
                    param['id']  = id;
                }
                param['name']  = name;
                param['description']  = description;
                param['specialty']  = specialty;
                param['degree']  = degree;
                param['cityId']  = cityId;
                param['talentSource']  = source;
                param['graduateDate']  = graduateDate;
                param['returnee']  = returnee;
                param['createBy']  = createBy;

                $.ajax({
                    url: postUrl,
                    type: "POST",
                    dataType: "json",
                    data: JSON.stringify(param),
                    contentType: "application/json;charset=utf-8",
                    success: function(data, status){
                        if (data.errorcode == "0"){
                            alert("发布成功");
                            var uri = '${ctx}/wechat/hunter/school/schJob/list'
                            window.location.href = uri;
                        }else{
                            alert(data.msg);
                            $(that).removeClass('disabled');
                        }
                    },
                    error: function(){
                        alert("服务出错，请稍后尝试");
                        $(that).removeClass('disabled');
                    }
                });
            }
        }
    };

    $('.button').on('click', handler.activate);

    var dataarray = "${job.cityId}".split(",");
    $('#cityId').dropdown('set value', dataarray);
    var dataarray1 = "${job.talentSource}".split(",");
    $('#source').dropdown('set value', dataarray1);

    $('.dropdown').dropdown({
        maxSelections: 3,
        fullTextSearch:true
    });

    wx.ready(function() {
        wx.hideOptionMenu();
    });

</script>

</form>
</div>
</div>
</div>
</body>
</html>